package com.lcc.intercepter;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * /**
 *
 * @author 廖聪聪
 * @version 1.0
 * 创建时间 2020/7/25 10:20
 */

public class GoDelalis implements HandlerInterceptor {
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
       //验证请求的地址是否是登录地址  如果是继续往下执行
		String uri = request.getRequestURI();
		uri = uri.substring(uri.lastIndexOf("/") + 1);
		System.out.println("uri"+uri);
		if (uri.equals("gobuy")&&request.getSession().getAttribute("user")!= null) {
			return true;
		}
		//执行跳转到登录页面
		response.sendRedirect(request.getContextPath() + "/login.jsp");
		return false;
	}

	public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

	}

	public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

	}
}
